<template>
    <div class="box">
      <span>注册</span>
      <div class="content">
        <el-input v-model="phoneNumber"  placeholder="输入用户名或者手机号" style="width: 400px;margin: 10px 0;"  clearable >
            <template #prepend>
                手机号
            </template>
        </el-input>

        <el-input v-model="code"  placeholder="输入验证码" style="width: 400px;margin: 10px 0;"  clearable >
            <template #append>
                发送验证码
            </template>
        </el-input>

        <el-input v-model="name"  placeholder="请输入真实姓名"  style="width: 400px;margin: 10px 0;" >
            <template #prepend>
                姓名
            </template>
        </el-input>
        <el-input v-model="IDCard"  placeholder="请输入身份证号"  style="width: 400px;margin: 10px 0;" >
            <template #prepend>
                身份证号
            </template>
        </el-input>
        <el-input v-model="password"  placeholder="设置密码"  style="width: 400px;margin: 10px 0;" show-password clearable >
            <template #prepend>
                创建密码
            </template>
        </el-input>
        <el-input v-model="ispassword"  placeholder="再次确认密码"  style="width: 400px;margin: 10px 0;" show-password clearable >
            <template #prepend>
                确认密码
            </template>
        </el-input>
      </div>

      <div class="footer">
        <el-button class="button" type="primary" @click="Register">注册</el-button>
      </div>
      <div class="back">
        <el-button v-for="button in buttons" :key="button.text" :type="button.type" link @click="back">
        {{ button.text }}
        </el-button>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  import { useRouter } from "vue-router";
  const router = useRouter();
  const todos = ref([])
  const phoneNumber = ref('')
  const code = ref('')
  const name = ref('')
  const IDCard = ref('')
  const password = ref('')
  const ispassword = ref('')

  const buttons = [
    { type: 'primary', text: '返回首页' },
  ]

const Register=()=>{
  // 重定义值
    let phoneNumbers=phoneNumber.value
    let codes=code.value
    let names=name.value
    let IDCards=IDCard.value
    let passwords=password.value
    let ispasswords=ispassword.value
    // 赋值给数组
    let todo = { id: Date.now(), phoneNumbers, codes, names, IDCards, passwords, ispasswords};
    todos.value = todo;

    let msg= phoneNumbers !==''&&codes!==''&&names!==''&&IDCards!==''&&passwords!==''&&ispasswords!==''
    if(msg){
        alert('恭喜注册成功！！')
        router.push({ path: "/login" });
    }else{
      alert('请完善信息')
    }
  }
const back=()=>{
    router.push({ path: "/login" });

}
  </script>
  
  <style lang="scss" scoped>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .box {
    width: 500px;
    height: 500px;
    border: 2px solid skyblue;
    margin: 50px auto;
    border-radius: 10px;
    span{
      display: block;
      font-size: 30px;
      text-align: center;
      color: skyblue;
    }
    .content{
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      margin: 5px 0;
    }
    
    .footer{
      display: flex;
      justify-content: space-around;
      align-items: center;
      .button{
        width: 100px;
        margin-top: 30px;
      }
    }
    .back{
      display: flex;
      justify-content: end;
      margin-right: 50px;
      margin-top: 10px;
    }
  }
  </style>